<?php
include_once('common/header.php');
if($AppUI->id <= 0 || (isset($_SESSION['news']) && ($_SESSION['news'] <= 0))) {
	Vfriend_Function::redirect(HOST_BACKEND);
}
$arrParams 	= $objRequest->getParams();
$intAction 	= isset($arrParams['paction']) ? $arrParams['paction'] : 0;
$intDetail = isset($arrParams['de']) ? $arrParams['de'] : 0;
$intNewId = isset($arrParams['newid']) ? $arrParams['newid'] : null;
$arrNewId 	= isset($arrParams['pnewid']) ? $arrParams['pnewid'] : null;
$strBackUrl	= isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : HOST_BACKEND;
$intError  	= 0;
if($intAction && (isset($arrNewId) || isset($intNewId))) {
	$objNews	= new News();
	switch ($intAction) {
		case 1: // active
		case 5: // cancel report		
			if(isset($_SESSION['news']) && ($_SESSION['news']&1<<5) != 0) {	
				if($intAction == 1 || $intAction == 5) $intStatus = 1;
				if($intDetail == 0) {
					foreach($arrNewId as $row) {
						$intError  = $objNews->updateStatus($AppUI->id,$row,$intStatus,32);
					}
				} else {
					$intError  = $objNews->updateStatus($AppUI->id,$intNewId,$intStatus,32);
				}
			}
			else {
				$intError = 1;
			}
			break;
		case 2: // delete
			if(isset($_SESSION['news']) && ($_SESSION['news']&1<<3) != 0) {
				if($intDetail == 0) {
					foreach($arrNewId as $row) {
						$objNews->updateStatus($AppUI->id,$row,3,8);
					}
				} else {
					$intError  = $objNews->updateStatus($AppUI->id,$intNewId,3,8);
				}
			}
			else {
				$intError = 1;
			}
			break;
		case 3://suspend
			if(isset($_SESSION['news']) && ($_SESSION['news']&1<<4) != 0) {	
				if($intDetail == 0) {
					foreach($arrNewId as $row) {
						$intError  = $objNews->updateStatus($AppUI->id,$row,2,16);
					}
				} else {
					$intError  = $objNews->updateStatus($AppUI->id,$intNewId,2,16);
				}
			}
			else {
				$intError = 1;
			}
			break;
		case 4: // delete database
			if(isset($_SESSION['news']) && ($_SESSION['news']&1<<3) != 0 && $AppUI->type > 1) {
				if($intDetail == 0) {
					foreach($arrNewId as $row) {
						$objNews->delete($AppUI->id,$row);
					}
				} else {
					$objNews->delete($AppUI->id,$intNewId);
				}
			}
			else {
				$intError = 1;
			}
			break;	
	}
} else {
	$intError = 1;
}
if($intError == 0) {
	Vfriend_Function::setMsg($arrMessage[$intAction]);
} else {
	Vfriend_Function::setError($arrError[$intError]);	
}
if($intDetail == 0) {
	Vfriend_Function::redirect($strBackUrl);
} else {
	$strRefer	= $objRequest->getParam('refer','');	
	Vfriend_Function::redirect(HOST_BACKEND . 'news/detail?newid=' . $intNewId . '&refer=' . $strRefer);
}

?>